<?php 
require "include/mail/swift_required.php";
$numSent = 0;
if ($_POST) {
	$header =  "<html><body><b>Formulario men&uacute; pedido - via: www.mifoodcourt.com</b><hr/>";
	$header .= "<b>Nombres: </b>". $_POST['txtnomb'] . "<br/>";
	$header .= "<b>Zona: </b>". $_POST['zona'] . "<br/>";	
	$header .= "<b>Direcci&oacute;n: </b>". $_POST['txtdirec'] . "<br/>";
	$header .= "<b>Tel&eacute;fono: </b>". $_POST['txtfono'] . "<br/>";
	$header .= "<b>Email: </b>". $_POST['txtmail'] . "<br/>";
	$header .= "<b>Fecha: </b>". date('l jS \of F Y h:i:s A'). "<br/>";
	$header .=  "<b>Platos: </b></br>";
	if (sizeof($_POST["menu"])>0) {
		$pPageIsPublic = true;
		include '_include.php';
		include '_core.php';
		include '_class.php';
		
		$st = 0;
		/*foreach ($_POST["menu"] as $id => $cant) {
			$item = new Menu();
			$item ->setUid($id);
			if ($item ->load()) {
				$header .=  "(*) {$item ->titulo} - S/. {$item ->precio}". " - Cant:{$cant}<br/>";
			}
			$st += $item ->precio * intval($cant);  
		}*/
		
		foreach ($_POST["menu"] as $k => $v) {
			$item = new Menu();
			$item ->setUid($k);
			if ($item ->load()) {
				$header .=  "(*) {$item ->titulo} - S/. {$item ->precio}". " - Cant:{$v["q"]}<br/>";
				if (strlen(trim($v["asset"]))>0) {
					$tmp = new MenuConfigDetalle();
					$tmp ->addWhere($tmp ->getIdKey() . " IN (". $v["asset"] .")");
					$tmp ->loadList();
					$header .= "<ul>";
					while ($detail =  $tmp ->rNext()) 
						$header .= "<li>{$detail ->menuconfig ->titulo}: {$detail ->titulo}</li>";
					$header .= "</ul>";
				}
			}
			$st += $item ->precio * intval($v["q"]);
		}
		
		
	$header .=  "<hr/>";
	$header .= "<b>Sub Total: S/.</b>". number_format($st, 2) . "<br/>";
	$header .= "<b>Servicio Delivery: S/. </b>4.00<br/>";
	$header .= "<b>Total: S/.</b>". ($st + 4.0) . "<br/>";
		
	}
	$header .=  "</body></html>";
	
	$transport = Swift_SmtpTransport::newInstance();
	$mailer = Swift_Mailer::newInstance($transport);
	$message = Swift_Message::newInstance ("Formulario menu pedido - mifoodcourt.com")
	->setFrom ( array ('info@mifoodcourt.com' => 'mifoodcourt.com' ) )
	->setTo ( array ('jjbaraybar@mifoodcourt.com', 'jorge.ramirez@mgsolutech.com', 'jhon-henry1@hotmail.com'))
	->setCc (  array ($_POST['txtmail']) )
	->setBody ( $header, 'text/html' );

	$numSent = ( $mailer->batchSend ( $message ) != 0 ) ? 1 : 0 ;
}
die(var_dump($numSent));